﻿using System.Web;
using Eneta.Portal.Common.Repository;
using Microsoft.SharePoint;

namespace Eneta.Portal.Tooltips.Handlers
{
    public class TooltipHandler : IHttpHandler
    {
        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            var request = context.Request;
            var pageName = request["pg"];
            var areaName = request["area"];

            var repository = new TooltipRepository(SPContext.Current.Web);
            var tooltip = repository.GetTooltipFor(pageName, areaName);

            var response = context.Response;

            response.Clear();
            response.ClearHeaders();

            response.ContentType = "text/html";
            response.Write("<p>");

            if (tooltip != null)
                response.Write(tooltip.Description);

            response.Write("</p>");

            response.Flush();
            response.End();
        }
    }
}
